<template>
  <Card>
    <p slot="title">安全隐患态势情况</p>
    <div class="chart" id="chart-danger-dynamic"></div>
    <Divider />
    <span class="text">产生隐患的单位：{{count}}家</span>
    <Spin v-show="loading" fix size="large" />
  </Card>
</template>

<script>
import axios from 'axios'
export default {
  name: "",
  data() {
    return {
        loading:false,
        option:null,
        count:0
    };
  },
  methods: {
    renderChart() {
      this.loading = true;
      this.option = {
        legend: {
          top: "top",
          left: "center",
          orient: "horizontal",
          data: ["安全", "轻微告警", "中等告警", "严重告警"],
          textStyle: { fontSize: 12 }
        },
        tooltip: { show: true, trigger: "item", formatter: "{a} - {b}:{c}" },
        color: ["#00cf33", "#ffe300", "#fa7c00", "#fa2200"],
        series: [
          {
            name: "总体安全情况",
            type: "pie",
            radius: "55%",
            center: ["50%", "50%"],
            data: [],
            itemStyle: {
              normal: {
                shadowOffsetX: 3,
                shadowOffsetY: 3,
                shadowBlur: 7,
                shadowColor: "#00000033"
              }
            },
            label: {
              normal: {
                show: true,
                position: "outside",
                fontSize: 12,
                formatter: "{b}:{c}家"
              }
            }
          }
        ]
      };
      let params = {
        indexDate: this.dateShift(0) + ' 23:59:59'
      };
      axios
        .get(this.URLHEAD_TA + "ICoordinatesTitle", {
          params: params
        })
        .then(res => {
          let json = res.data;
          this.count = json.Data.slightCount+json.Data.mediumCount+json.Data.severityCount;
          this.option.series[0].data = [
            { name: "安全", value: json.Data.safetyCount },
            { name: "轻微告警", value: json.Data.slightCount },
            { name: "中等告警", value: json.Data.mediumCount },
            { name: "严重告警", value: json.Data.severityCount }
          ];
          this.$Crender("chart-danger-dynamic", this.option);
          this.loading = false;
        });
    },
  },
  mounted() {
      this.renderChart()
  },
};
</script>

<style scoped>
.chart{
    height:350px;
}
</style>